View on GitHub
View on GitHub

FluxBase

Provides core types and functionality to implement applications using Flux architecture with .NET.

FluxBase / Store / SetProperty<TProperty>(Expression<Func<TProperty>>, TProperty) Method

Dynamically updates a property and notifies observers about the change.

This is a protected method.

protected void SetProperty<TProperty>(Expression<Func<TProperty>> property, TProperty value)

Generic Parameters

Parameters

Exceptions

Remarks

This method simplifies stores by removing the boilerplate code for writing properties that notify observers upon change. Using this method the store class can have less clutter. Without using this method the store would look something like this:

public class MyStore : Store
{
    private int _value1;

    public int Property1
    {
        get => _value1;
        set
        {
            _value1 = value;
            NotifyPropertyChanged(nameof(Property1)); // or just NotifyPropertyChanged()
        }
    }

    protected override void Handle(Action action)
    {
        Property1++;
    }
}

Using SetProperty will simplify this to the following:

public class MyStore : Store
{
    public int Property1 { get; private set; }

    protected override void Handle(Action action)
    {
        SetProperty(() => Property1, Property1 + 1);
    }
}

There is no need to explicitly back properties with a field and manually raise the PropertyChanged event. This is all done by the SetProperty method.

This method is not available for .NET Framework 2.0 and .NET Framework 3.0 builds.

See Also